Skip to content

repl: add syntax highlighting, auto-indentation, and signature hints#64443

Open
hemanth wants to merge 1 commit into
nodejs:mainfrom
hemanth:repl/experimental-enhancements
Open

repl: add syntax highlighting, auto-indentation, and signature hints#64443
hemanth wants to merge 1 commit into
nodejs:mainfrom
hemanth:repl/experimental-enhancements

Conversation

@hemanth

@hemanth hemanth commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Description

Add experimental REPL enhancements behind the --experimental-repl-enhancements CLI flag:

1. Inline Syntax Highlighting

Uses the Acorn tokenizer (already in deps/) to colorize JavaScript input in real-time:

  • Keywords (const, function, if, etc.) → Magenta
  • Strings → Green
  • Numbers → Yellow
  • Booleans/null/undefined → Yellow
  • Regular expressions → Red
  • Comments → Gray

Highlighting is applied at display time only — repl.line remains plain text, so cursor positioning and evaluation are unaffected.

2. Auto-Indentation

Automatically inserts 2-space indentation on continuation lines based on brace/bracket/paren depth when entering multiline input.

3. Function Signature Hints

When the user types functionName(, the function's parameter list is displayed as a dimmed hint below the input line. Uses the V8 Inspector protocol with throwOnSideEffect: true for safety.

Usage

node --experimental-repl-enhancements

All features are off by default — nothing changes for users unless they explicitly pass the flag. Individual features can also be controlled via repl.start() options (e.g., syntaxHighlighting: false).

Motivation

This addresses the feature requests from #48164, which was closed as not planned. However, by gating everything behind an experimental flag with no behavioral changes to the default REPL, the risk profile is minimal. These are quality-of-life improvements that bring the Node.js REPL closer to modern shell experiences (Python's IPython, Ruby's Pry, etc.).

Refs: #48164

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jul 12, 2026
@hemanth hemanth force-pushed the repl/experimental-enhancements branch 4 times, most recently from 30413de to 14baff1 Compare July 12, 2026 07:02
@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.65269% with 132 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.20%. Comparing base (14166a5) to head (eec5763).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/repl/utils.js 70.79% 131 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64443      +/-   ##
==========================================
- Coverage   90.23%   90.20%   -0.03%     
==========================================
  Files         741      741              
  Lines      241375   242165     +790     
  Branches    45483    45628     +145     
==========================================
+ Hits       217800   218454     +654     
- Misses      15129    15247     +118     
- Partials     8446     8464      +18     
Files with missing lines Coverage Δ
lib/repl.js 94.19% <100.00%> (+0.18%) ⬆️
src/node_options.cc 76.65% <100.00%> (-0.08%) ⬇️
src/node_options.h 98.02% <100.00%> (+<0.01%) ⬆️
lib/internal/repl/utils.js 87.56% <70.79%> (-8.83%) ⬇️

... and 56 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hemanth hemanth force-pushed the repl/experimental-enhancements branch 2 times, most recently from 16ee02c to b749718 Compare July 12, 2026 20:37

@avivkeller avivkeller left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these be idiomatic PRs?

@hemanth

hemanth commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

@avivkeller for sure! having some challenges on my local machine, so depending on the GH CI to report me the build time errors.

@hemanth hemanth force-pushed the repl/experimental-enhancements branch 2 times, most recently from 1e7bcec to 088a905 Compare July 13, 2026 00:01
@hemanth hemanth requested a review from avivkeller July 13, 2026 02:34
@edsadr

edsadr commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

this one has been in my list forever; I thik this should dogfood util.styleText and make use of everything about coloring already existing in core

@hemanth

hemanth commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Agree. util.styleText reminded me of #43371

Add experimental REPL enhancements behind the
--experimental-repl-enhancements flag:

1. Inline syntax highlighting using the Acorn tokenizer
   to colorize keywords (magenta), strings (green),
   numbers (yellow), booleans/null (yellow), regular
   expressions (red), and comments (gray).

2. Auto-indentation for multiline input based on
   brace/bracket/paren depth, using 2-space indentation.

3. Function signature hints that display parameter lists
   as dimmed text below the input when the user types a
   function call.

All features are off by default and require the CLI flag
to enable. Highlighting is applied at display time only
so cursor positioning and evaluation are unaffected.

Refs: nodejs#48164
Signed-off-by: hemanth <hemanth.hm@gmail.com>
Comment thread doc/api/cli.md
added: REPLACEME
-->

> Stability: 1 - Experimental

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling we should just enable it by default in a semver-major as long as it respects the NO_COLOR or FORCE_TTY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants